const app = getApp()
import global from "../../../utils/global"
import { applyGroupPolicy } from "../../api/insurance"
Page({
    data: {
        titleTop: '',
        operatorName:'', // 姓名
        operatorIdCard:'',// 身份证
        accountLimit:'',// 账户
        contact:'',// 手机号
        fileUrl:''
    },
    onLoad(options) {

    },
    onReady() {

    },
    onShow() {
        this.setData({
            titleTop: Number(app.globalData.menuTop)
        })
    },
    upload(){
        wx.chooseMedia({
            count:1,
            mediaType: ['image'],
            sourceType: ['album', 'camera'],
            sizeType: ['compressed'],
            success:(res)=>{
                wx.uploadFile({
                    url:global.baseUrl + '/api/v1/pay/wesure-report-case/upload',
                    filePath:res.tempFiles[0].tempFilePath,
                    name:'file',
                    success:(res)=>{
                        console.log(res, '返回给我的')
                        this.setData({
                            fileUrl: JSON.parse(res.data).data.fileUrl
                        })
                    },
                })
            }
        })
    },
    // 确定上传
    async onSubmit(){
        if(!this.data.accountLimit){
            app.toast('请填写账户')
            return
        }
        if(/[\u4e00-\u9fa5]/.test(this.data.accountLimit)){
            app.toast('账户不允许包含汉字')
            return
        }
        if(!this.data.operatorName){
            app.toast('请填写姓名')
            return
        }
        if(!this.data.operatorIdCard){
            app.toast('请填写身份证')
            return
        }
        if(!this.data.contact){
            app.toast('请填写手机号')
            return
        }
        if(!this.data.fileUrl){
            app.toast('请上传营业执照')
            return
        }
        await applyGroupPolicy({
            operatorName:this.data.operatorName, 
            operatorIdCard:this.data.operatorIdCard,
            accountLimit:this.data.accountLimit,
            contact:this.data.contact,
            fileUrl:this.data.fileUrl
        })
        await wx.redirectTo({
            url: '/packageMicroInsurance/pages/application-state/application-state?state=1&name=该申请通过后会及时通知超级管理员&title=提交成功！&tips=请关注微信通知' ,
        })
    }
})